/*****************************************************************************/
/** \file mc_obse.h
**
** 
**
** History:
** 
*****************************************************************************/
#ifndef  __MC_OBSE_H__
#define  __MC_OBSE_H__

/*****************************************************************************/
/* Include files */
/*****************************************************************************/

/*****************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/*****************************************************************************/
#define	 	u8   						unsigned char 
#define   	s32							signed int 
	
#define		_IQ15(x)					(u16)((x)*32767)
#define		_IQmpy(x,y) 				(((x)*(y))>>15)
#define 	_IQabs(Value)			 	((Value)>=0?(Value):-(Value))
#define		_IQdiv(x,y)					(HWDIV_Div((x),(y)))

#define     KLPF_We        				(3658)

#define     VBUS_ENABLE       			(1)
#define     VBUS_DISABLE       			(0)

/*****************************************************************************/
/* Global type definitions ('typedef') */
/*****************************************************************************/
typedef struct 
{  
	s32  Valpha;    // Input: Stationary alfa-axis stator voltage 
 
	s32  Ealpha;   // Variable: Stationary alfa-axis back EMF 

	s32  Zalpha;      // Output: Stationary alfa-axis sliding control 

	s32  Gsmopos;    // Parameter: Motor dependent control gain 

	s32  EstIalpha;   // Variable: Estimated stationary alfaaxis stator current 

	s32  Fsmopos;    // Parameter: Motor dependent plant matrix 

	s32  Vbeta;    // Input: Stationary beta-axis stator voltage 

	s32  Ebeta;   // Variable: Stationary beta-axis back EMF 

	s32  Zbeta;      // Output: Stationary beta-axis sliding control 

	s32  EstIbeta;    // Variable: Estimated stationary beta-axis statorcurrent 

	s32  Ialpha;   // Input: Stationary alfa-axis stator current 

	s32  IalphaError; // Variable: Stationary alfaaxis current error                 

	s32  Kslide;     // Parameter: Sliding control gain 

	s32  Ibeta;   // Input: Stationary beta-axis stator current 

	s32  IbetaError;  // Variable: Stationary betaaxis current error                 

	s32  Kslf;       // Parameter: Sliding control filter gain 

	s32  Theta;     // Output: Compensated rotor angle 
	
	s32  ThetaRamp;     // Output: Compensated rotor angle 
	
	s32  DeltaTheta;     // Output: DeltaTheta	
	
	s32  We;     // Output: Compensated rotor we
	
	s32  Speed;     // Output: Compensated rotor we
		
	s32  Freq;     // Output: Compensated rotor we
			
	s32  We_Limit;     // Output: Compensated rotor we
	
	s32  E0;     // Output: Compensated rotor angle 
 
	s32  Angle;     // Output: Compensated rotor angle 
	
	u8	 KBW;
 
} T_SMO;             
 
/*****************************************************************************/
/* Global variable declarations ('extern', definition in C source) */
/*****************************************************************************/
extern T_SMO		t_Obse; 

/*****************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/*****************************************************************************/
extern void 		MC_Observer_Calc(T_SMO *v);
extern void 		MC_Obse_Init(T_SMO *v);
extern void			MC_ObsePara_Init(void);
extern void 		MC_ROT_Theta_Calc(T_SMO *E);
extern s32 			Get_RotElec_Angle(void);

#endif	 /* __MC_OBSE_H__ */
 

